package com.mljr.example.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ctakit.sdk.app.utils.DensityUtil;
import com.ctakit.sdk.app.widget.tab.home.HomeTabLayout;
import com.mljr.example.R;
import com.mljr.example.bean.TabModel;

public class HomeTabAdapter  extends HomeTabLayout.AbsTabAdapter<TabModel> {
    public static final int ITEM_ID_CENTER = 1008;

    public HomeTabAdapter(Context context) {
        super(context, R.layout.widget_home_tab_layout_item);
    }

    @Override
    public View getView(TabModel model, View root) {
        TextView mTxtTitle = (TextView) root.findViewById(R.id.mTxtTitle);
        ImageView mImgIcon = (ImageView) root.findViewById(R.id.mImgIcon);
        mTxtTitle.setText(model.getTitle());
        mImgIcon.setImageResource(model.getIconId());
        mTxtTitle.setSelected(model.isSelected());
        mImgIcon.setSelected(model.isSelected());

        if (model.getId() == ITEM_ID_CENTER) {
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) (mImgIcon.getLayoutParams());
            layoutParams.bottomMargin = DensityUtil.dip2px(7);
            mImgIcon.setPadding(DensityUtil.dip2px(0.5f),0,0,0);
            mTxtTitle.setSelected(true);
        }
        return root;
    }
}